package ru.cybertek.dao.impl.jdbc;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.SqlUpdate;

import ru.cybertek.domain.Person;

/**
 * @author Dmitry Demyankov
 * @version $Revision: 10 $
 * 
 *          (C) Copyright 2009 CyberTek Ltd. All rights reserved.
 */
public class DeletePersonSqlQuery extends SqlUpdate
{
    public static final String DELETE_PERSON_SQL_QUERY = "DELETE FROM person WHERE id = :id";
    
    public static final String PERSON_ID_PARAMETER = "id";
    
    /**
     * @param dataSource
     */
    public DeletePersonSqlQuery(DataSource dataSource)
    {
        setDataSource(dataSource);
        setSql(DELETE_PERSON_SQL_QUERY);
        declareParameter(new SqlParameter(Types.INTEGER));
        compile();
    }
    
    /**
     * @param person
     * @throws DataAccessException
     */
    public void execute(Person person) throws DataAccessException
    {
        Map<String, Object> namedParameters = new HashMap<String, Object>(1);
        namedParameters.put(PERSON_ID_PARAMETER, person.getId());
        
        super.updateByNamedParam(namedParameters);
    }
}
